import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import axios from 'axios';

export default function Home() {
  const navigate = useNavigate();

  useEffect(() => {
    const checkAuthStatus = async () => {
      try {
        const response = await axios.post('http://localhost:3000/api/check-auth', {}, {
          withCredentials: true
        });
        
        if (response.data.isAuthenticated) {
          navigate('/dashboard');
        } else {
          navigate('/login');
        }
      } catch (error) {
        console.error('认证检查失败:', error);
        navigate('/login');
      }
    };

    checkAuthStatus();
  }, [navigate]);

  return null; // 不需要渲染任何内容，仅做路由跳转
}
